%Image Processing Assignment - 8
%Name: - Kirtish Dhande
%Class: - B.E. - C
%Roll no: - 54
% This program is for huffman coding
%Date of assignment - 29/03/2016

%
clc;
clear all;
%a=input('Enter string')
a='COMMITTEE'
s='';
s=unique(a);
n= length(s);
l=length(a);
count =0;
for i=1:n
    for j=1:l
        if s(i)==a(j)
            count=count+1;
            p(i)=count/l;
        end
    end
    fprintf('\np(%c) = %f',s(i),p(i));
    count=0;
end
 
if length(s)~=length(p)
   error('Wrong entry.. enter again- ') 
end   
 
i=1;
for m=1:length(p)
   for n=1:length(p)
       if(p(m)>p(n))
         a=p(n);  a1=s(n);
         p(n)=p(m);s(n)=s(m);  
         p(m)=a;   s(m)=a1;
       end
   end
end
display(p) %arranged prob. in descending order.
display(s) %arranged alphabet according to probability
 
tempfinal=[0];
sumarray=[];
w=length(p);
lengthp=[w];
b(i,:)=p;
c=huffman(p);
display(c);
